import { AssistantDetail } from '@/types/assistant'
import axios from '../request'

export interface AssistantItemDB {
  create_time: string
  desc: string
  id: string
  logo?: string
  name: string
  update_time: string
  user_id: number
  user_name: string
  status: number
}
// 获取助手列表
export const getAssistantsApi = async (page, limit, name, category_code, status): Promise<AssistantItemDB[]> => {
  return await axios.get('/api/v1/assistant', {
    params: {
      page,
      limit,
      name,
      category_code,
      status
    }
  })
}

// 创建助手
export const createAssistantsApi = async (name, desc, logo, category_code, query_template) => {
  return await axios.post('/api/v1/assistant', { name, desc, logo, category_code, query_template })
}

// 获取助手详情
export const getAssistantDetailApi = async (id): Promise<AssistantDetail> => {
  return await axios.get(`/api/v1/assistant/info/${id}`)
}

// 获取助手系统模型
export const getAssistantModelsApi = async (company_id = null): Promise<any> => {
  return await axios.get('/api/v1/assistant/models' + `?company_id=${company_id}`)
}

// 上下线助手
export const changeAssistantStatusApi = async (id, status) => {
  return await axios.post('/api/v1/assistant/status', { id, status })
}

// 保存助手
export const saveAssistanttApi = async (
  data: Omit<AssistantDetail, 'flow_list' | 'tool_list' | 'knowledge_list'> & {
    flow_list: string[] | any
    tool_list: number[]
    knowledge_list: number[]
  }
): Promise<any> => {
  return await axios.put('/api/v1/assistant', data)
}

// 删除助手
export const deleteAssistantApi = async id => {
  return await axios.post(`/api/v1/assistant/delete?assistant_id=${id}`)
}

// 获取会话选择列表
export const getChatOnlineApi = async () => {
  return await axios.get('/api/v1/chat/online')
}

// 获取插件集合
export const getPublished_list = async (is_preset, is_custom, categoryCode = '', is_published = null): Promise<any> => {
  const data = {
    is_preset,
    is_custom,
    page: 1,
    limit: 10000,
    category_code: categoryCode || null,
    is_published
  }

  return await axios.post('/api/v1/tools/tools_list', data)
}

export type conditionsParamsType = {
  id: string
  type: string
  user: string
  platform: string
  timeRange: [number, number]
}

// 查询数据智能体看板信息
export const getAstDataBoardInfoApi = async (conditions: conditionsParamsType) => {
  return await axios.post('/api/v1/dashboard/board_info', conditions)
}
